package com.small.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Properties;

/**
 * @author syd
 * @create 2020-12-12 8:52
 */
public class PropertiesUtil {

    //获取配置文件内容
    public void getProperties(Properties prop) throws IOException {

        //1.获取jar包所在目录
        String path=this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
        path = path.substring(1, path.lastIndexOf("/"));
        String decode = URLDecoder.decode(path, "UTF-8");

        //2.获取app.properties文件内容
        BufferedReader bufferedReader = new BufferedReader(new FileReader(decode + "\\app.properties"));

        prop.load(bufferedReader);

        //System.out.println(decode);

    }

    //获取jar包路径
    public String getPath(){
        return this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    }

    public static void main(String[] args) throws IOException {
/*        PropertiesUtil propertiesUtil = new PropertiesUtil();
        Properties prop=new Properties();

        propertiesUtil.getProperties(prop);*/

    }

}
